package com.ruoyi.live.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.live.domain.LiveStream;
import com.ruoyi.live.service.ILiveStreamService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 查询直播房间Controller
 * 
 * @author ruoyi
 * @date 2023-04-09
 */
@Controller
@RequestMapping("/live/Stream")
public class LiveStreamController extends BaseController
{
    private String prefix = "live/Stream";

    @Autowired
    private ILiveStreamService liveStreamService;

    @RequiresPermissions("live:Stream:view")
    @GetMapping()
    public String Stream()
    {
        return prefix + "/Stream";
    }

    /**
     * 查询查询直播房间列表
     */
    @RequiresPermissions("live:Stream:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LiveStream liveStream)
    {
        startPage();
        List<LiveStream> list = liveStreamService.selectLiveStreamList(liveStream);
        return getDataTable(list);
    }

    /**
     * 导出查询直播房间列表
     */
    @RequiresPermissions("live:Stream:export")
    @Log(title = "查询直播房间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LiveStream liveStream)
    {
        List<LiveStream> list = liveStreamService.selectLiveStreamList(liveStream);
        ExcelUtil<LiveStream> util = new ExcelUtil<LiveStream>(LiveStream.class);
        return util.exportExcel(list, "查询直播房间数据");
    }

    /**
     * 新增查询直播房间
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存查询直播房间
     */
    @RequiresPermissions("live:Stream:add")
    @Log(title = "查询直播房间", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LiveStream liveStream)
    {
        return toAjax(liveStreamService.insertLiveStream(liveStream));
    }

    /**
     * 修改查询直播房间
     */
    @RequiresPermissions("live:Stream:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LiveStream liveStream = liveStreamService.selectLiveStreamById(id);
        mmap.put("liveStream", liveStream);
        return prefix + "/edit";
    }

    /**
     * 修改保存查询直播房间
     */
    @RequiresPermissions("live:Stream:edit")
    @Log(title = "查询直播房间", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LiveStream liveStream)
    {
        return toAjax(liveStreamService.updateLiveStream(liveStream));
    }

    /**
     * 删除查询直播房间
     */
    @RequiresPermissions("live:Stream:remove")
    @Log(title = "查询直播房间", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(liveStreamService.deleteLiveStreamByIds(ids));
    }
}
